package hot;

/**
 * @author lakersUp
 * @Classname
 * @Description
 * @Date 2022/3/10 10:08
 * @Version 1.0
 */
public class Hot75sortColors {
    public void sortColors(int[] nums) {
        int n=nums.length;
        int left=0;
        int count=0;
        int right=n-1;
        while(count<n && count<=right){
            if(nums[count]==0){
                swap(nums,count,left);
                left++;
                count++;
            }else {
                if(nums[count]==1){
                    count++;
                }else {
                    swap(nums,count,right);
                    right--;
                }
            }
        }
    }
    private void swap(int[] nums, int a, int b) {
        int tmp=nums[a];
        nums[a]=nums[b];
        nums[b]=tmp;
    }
}
